package com.example.newncee;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;

import com.example.newncee.ui.login.LoginActivity;
import com.google.android.material.bottomnavigation.BottomNavigationView;

/**
 * @author Sora
 * time: 2022/2/11 23:18
 * description: main activity, display school and user info
 * provide function of school screening and user info modifing
 */
public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        BottomNavigationView navView = findViewById(R.id.nav_view);
        // Passing each menu ID as a set of Ids because each
        // menu should be considered as top level destinations.
        AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
                R.id.navigation_home,R.id.navigation_notifications)
                .build();
        NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
//        NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
        NavigationUI.setupWithNavController(navView, navController);
    }

    public void modifyInfo(View view) {
        Log.e("test","111");
        AlertDialog.Builder builder=new AlertDialog.Builder(view.getContext());
        builder.setMessage("请确认修改");
        builder.setCancelable(true);
        builder.setPositiveButton("是", (dialog, which) -> {
            SharedPreferences sp=getSharedPreferences("user",MODE_PRIVATE);
            @SuppressLint("CommitPrefEdits") SharedPreferences.Editor et=sp.edit();
            et.clear();
            et.apply();
            dialog.dismiss();
            startActivity(new Intent(MainActivity.this, LoginActivity.class));
        });
        builder.setNegativeButton("否", (dialog, which) -> {
           dialog.dismiss();
        });
        builder.create().show();
    }
}